package com.chalk.controller;

import com.chalk.rabbitmq.MqSender;
import com.chalk.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xiaoqiang
 * @Description
 * @date 2019/7/16 16:32
 */
@Controller
public class RabbitController {
    @Autowired
    MqSender mqSender;

    @RequestMapping("/mq/header")
    @ResponseBody
    public Result<String> header() {
        mqSender.sendHeader("hello,rabbitmq,header");
        return Result.success("header");
    }

    @RequestMapping("/mq/fanout")
    @ResponseBody
    public Result<String> fanout() {
        mqSender.sendFanout("hello,rabbitmq,fanout");
        return Result.success("fanout");
    }

    @RequestMapping("/mq/topic")
    @ResponseBody
    public Result<String> topic() {
        mqSender.sendTopic("hello,rabbitmq,topic");
        return Result.success("topic");
    }

    @RequestMapping("/mq/{message}")
    @ResponseBody
    public Result<String> sendMq(@PathVariable("message") String message) {
        mqSender.send(message);
        return Result.success("direct");
    }
}
